package com.sgb.kjwl.view.ui.activity.transport.driver.lines;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityTransTransListBinding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.util.MToast;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by harisucici on 2020/4/7
 * Class description:常跑线路
 */
public class LineSettingActivity extends AppActivity {

    @Inject
    LineSettingModel lineSettingModel;
    private LineSettingAdapter adapter;
    private ActivityTransTransListBinding binding;
    private List<LinesItemEntity> mList = new ArrayList();


    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, LineSettingActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent
                .builder()
                .appComponent(appComponent)
                .transportModule(new TransportModule(this))
                .build()
                .inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_trans_trans_list);
        binding.include.ivBack.setOnClickListener(view -> onBackPressed());
        binding.include.titleView.setText("承运管理");
        binding.list.setLayoutManager(
                new LinearLayoutManager(this,
                        LinearLayoutManager.VERTICAL, false));
        adapter = new LineSettingAdapter(this, (binding, taskBean, i) -> {
            MToast.showToast(this, "add");
            mList.add(0, new LinesItemEntity());// 在顶部插入空数据
            setData(mList);

        }, (binding, taskBean, i) -> {
            MToast.showToast(this, "del");
            mList.remove(i);
            setData(mList);

        }, (binding, taskBean, i) -> {
            MToast.showToast(this, "add1");

        }, (binding, taskBean, i) -> {
            MToast.showToast(this, "add2");
        });
        binding.list.setAdapter(adapter);
        binding.setLifecycleOwner(this);


        // 初始化数据
        mList.add(0, new LinesItemEntity());
        setData(mList);

    }


    private void setData(List<LinesItemEntity> entities) {
        adapter.refreshData(entities);
    }


    @Override
    protected void init() {
    }

}
